#include "response.h"

namespace response {
    Response::Response(const std::string &msg, response::StatusCode code, const Json::Value &data) {
        (*this)["msg"] = msg;
        (*this)["code"] = static_cast<int>(code);
        (*this)["data"] = data;
    }

    std::string Response::getMsg() const {
        return (*this)["msg"].asString();
    }

    void Response::setMsg(const std::string &msg) {
        (*this)["msg"] = msg;
    }

    StatusCode Response::getCode() const {
        return static_cast<StatusCode>((*this)["code"].asInt());
    }

    void Response::setCode(StatusCode code) {
        (*this)["code"] = static_cast<int>(code);
    }

    Json::Value Response::getData() const {
        return (*this)["data"];
    }

    void Response::setData(const Json::Value &data) {
        (*this)["data"] = data;
    }

    SuccessResponse::SuccessResponse(const Json::Value &data)
            : Response("ok", response::StatusCode::Success, data) {}

    ErrorResponse::ErrorResponse(const std::string &msg, response::StatusCode code)
            : Response(msg, code, Json::Value()) {}

    UserExistsResponse::UserExistsResponse(const Json::Value &data)
            : Response("the user already exists", response::StatusCode::UserExists, data) {}

    UserDoesNotExistResponse::UserDoesNotExistResponse(const Json::Value &data)
            : Response("the user does not exist", response::StatusCode::UserDoesNotExist, data) {}

    WrongPasswordResponse::WrongPasswordResponse(const Json::Value &data)
            : Response("the account number or password is incorrect", response::StatusCode::WrongPassword, data) {}

    InvalidParametersResponse::InvalidParametersResponse(const Json::Value &data)
            : Response("parameter error", response::StatusCode::InvalidParameters, data) {}
}
